﻿using System;
using System.Data;
using System.Text;
using Microsoft.Practices.EnterpriseLibrary.Data;
using System.Data.Common;

namespace Chenxin.Lib.Hr.DAL
{
    public class Structures
    {
        public Structures() { }
        /// <summary>
        /// 获取用户所控制的门店
        /// </summary>
        /// <param name="UserId"></param>
        /// <returns></returns>
        public static System.Data.DataSet GetUserControledDeparts(Guid UserId)
        {
            StringBuilder sb = new StringBuilder();
            sb.Append("select c.* ");
            sb.Append("from Hr_DepartmentInfo c ");
            sb.Append("where exists(select * from Struct_UserDepartRelation b ");
            sb.Append("where b.userId = @UserId AND c.departId = b.departId and b.IsControl=1) ");

            Database db = DatabaseFactory.CreateDatabase("Chenxin_Main_Search");
            DbCommand dbcommand = db.GetSqlStringCommand(sb.ToString());
            db.AddInParameter(dbcommand, "UserId", DbType.Guid, UserId);

            return db.ExecuteDataSet(dbcommand);
        }
    }
}
